#ifndef ROS_PROXY_HPP
#define ROS_PROXY_HPP

#include <QObject>
#include <QString>

class ROSProxy : public QObject
{
    Q_OBJECT
    // 1. 定义一个属性，用于在QML中绑定显示接收到的消息
    //    NOTIFY信号会在C++中更新此属性时通知QML刷新
    Q_PROPERTY(QString receivedMessage READ receivedMessage WRITE setReceivedMessage NOTIFY receivedMessageChanged)

public:
    explicit ROSProxy(QObject *parent = nullptr);

    QString receivedMessage() const;
    void setReceivedMessage(const QString &msg);

public slots:
    // 2. 这个槽用来接收来自子线程ROS节点的消息
    void onMessageReceived(const QString &msg);

    // 3. 这个Q_INVOKABLE方法供QML调用，用于发布消息
    Q_INVOKABLE void publishMessage(const QString &msg);

signals:
    // 4. 这个信号发射出去，去触发子线程中的ROS节点进行发布
    void doPublish(const QString &msg);

    // 属性的 NOTIFY 信号
    void receivedMessageChanged();

private:
    QString m_receivedMessage;
};

#endif // ROS_PROXY_HPP
